import React, { Component } from 'react'
// react-redux提供高阶组件
import { connect } from 'react-redux'
import * as actions from './store/actions/countAction'

// 装饰器
// 参数1 把redux中的state映射成为当前组件的props
// 参数2 mapPropsToDispatch
@connect(state=>(state),actions)
class App extends Component {

  render() {
    return (
      <div>
        App
        <h3>{this.props.count}</h3>
        <button onClick={this.incr}>++++</button>
      </div>
    )
  }

  incr = () => {
    this.props.incr()
  }

}

export default App

/* // 参数1 把redux中的state映射成为当前组件的props
const mapStateToProps = state => {
  return {
    count: state.count
  }
}

// 参数2 mapPropsToDispatch
const mapPropsToDispatch = dispatch => {
  return {
    incr() {
      // ajax
      dispatch(actions.incr())
    }
  }
}

export default connect(mapStateToProps, mapPropsToDispatch)(App)
 */
// 简写，直接写action creator {type payload}
// export default connect(mapStateToProps, actions)(App)


